﻿using Utils.Wpf;

namespace StockAnalyst2.Chart
{
	internal class ChartOptionsVM : ViewModelBase
	{
		#region Attributes

		private readonly Options _model;

		#endregion

		#region Properties

		public ChartSource ChartSource
		{
			get
			{
				return _model.DataSource;
			}
			set
			{
				if (_model.DataSource != value)
				{
					_model.DataSource = value;
					base.OnPropertyChanged("ChartSource");
				}
			}
		}

		public SeriesOptionsVM LastValueVM { get; private set; }
		public SeriesOptionsVM BidAskAverageVM { get; private set; }
		public SeriesOptionsVM BidVM { get; private set; }
		public SeriesOptionsVM AskVM { get; private set; }
		public SeriesOptionsVM SMA1VM { get; private set; }
		public SeriesOptionsVM SMA2VM { get; private set; }
		public SeriesOptionsVM SMA3VM { get; private set; }
		public SeriesOptionsVM StochasticVM { get; private set; }
		public SeriesOptionsVM GapVM { get; private set; }
		public SeriesOptionsVM TrixVM { get; private set; }
		public SeriesOptionsVM TrixChangeRatioVM { get; private set; }
		public SeriesOptionsVM VolumeVM { get; private set; }
		public SeriesOptionsVM TotalVolumeVM { get; private set; }
		public SeriesOptionsVM AverageVolumeVM { get; private set; }

		#endregion

		#region Public Methods

		public ChartOptionsVM(Options model)
		{
			_model = model;

			this.LastValueVM = new SeriesOptionsVM(model.LastValue);
			this.BidAskAverageVM = new SeriesOptionsVM(model.BidAskAverage);
			this.BidVM = new SeriesOptionsVM(model.Bid);
			this.AskVM = new SeriesOptionsVM(model.Ask);
			this.SMA1VM = new SeriesOptionsVM(model.SMA1);
			this.SMA2VM = new SeriesOptionsVM(model.SMA2);
			this.SMA3VM = new SeriesOptionsVM(model.SMA3);
			this.StochasticVM = new SeriesOptionsVM(model.Stochastic);
			this.GapVM = new SeriesOptionsVM(model.Gap);
			this.TrixVM = new SeriesOptionsVM(model.Trix);
			this.TrixChangeRatioVM = new SeriesOptionsVM(model.TrixChangeRatio);
			this.VolumeVM = new SeriesOptionsVM(model.Volume);
			this.TotalVolumeVM = new SeriesOptionsVM(model.TotalVolume);	
			this.AverageVolumeVM = new SeriesOptionsVM(model.AverageVolume);

			this.BidVM.PropertyChanged += this.BidVM_PropertyChanged;  // Local object
			this.AskVM.PropertyChanged += this.AskVM_PropertyChanged;  // Local object
		}

		#endregion

		#region Event Handlers

		private void AskVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
		{
			this.BidVM.IsEnabled = this.AskVM.IsEnabled;
			this.BidVM.DrawArea = this.AskVM.DrawArea;
			this.BidVM.AreaColor = this.AskVM.AreaColor;
		}

		private void BidVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
		{
			this.AskVM.IsEnabled = this.BidVM.IsEnabled;
			this.AskVM.DrawArea = this.BidVM.DrawArea;
			this.AskVM.AreaColor = this.BidVM.AreaColor;
		}

		#endregion
	}
}
